import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() =>
    runApp(MaterialApp(debugShowCheckedModeBanner: false, home: HomePage()));

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var _installStatus; // 首开标记

  @override
  void initState() {
    _isFirstInstall();
    super.initState();
  }

  @override
  Widget build(BuildContext context) => Scaffold(
        body: Center(
          child: _installStatus == null
              ? Text(
                  '首开',
                  style: TextStyle(fontSize: 32.0),
                )
              : Icon(Icons.wallpaper),
        ),
      );

  Future<void> _isFirstInstall() async {
    final pref = await SharedPreferences.getInstance();
    final status = pref.getBool('start');
    setState(() => _installStatus = status);
    status ?? await pref.setBool('start', true); // 异步设置布尔值,空值表示首开,true表示重开.
  }
}
